<?php

/**
 * MLayoutProjectDAO
 *
 * Classe que trata das operacoes relacionadas a persistencia de dados em Projetos de Layout
 *
 * @package models
 * @version
 */
class MLayoutProjectDAO extends Model {

    function MLayoutProjectDAO() {
        parent::Model();
    }

    public function insert($ip_user, $project_name, $project_content) {

    //monta a query
        $this->db->set('ip_user', $ip_user);
        $this->db->set('project_name', $project_name);
        $this->db->set('project_content', $project_content);
        //insere os dados
        $this->db->insert('layoutproject');
        if( $this->db->affected_rows() > 0 ) {
            return TRUE;
        }
        return FALSE;
    }

    public function update($ip_user, $project_name, $project_content) {

    //monta a query
        $this->db->set('project_content', $project_content);
        $this->db->where('ip_user', $ip_user);
        $this->db->where('project_name', $project_name);
        //atualiza o registro
        $this->db->update('layoutproject');
        if( $this->db->affected_rows() > 0 ) {
            return TRUE;
        }
        return FALSE;
    }

    public function delete($ip_user, $project_name) {

    //monta a query
        $this->db->where('ip_user', $ip_user);
        $this->db->where('project_name', $project_name);
        //remove o registro
        $this->db->delete('layoutproject');
        if( $this->db->affected_rows() > 0 ) {
            return TRUE;
        }
        return FALSE;
    }

     public function retrieve($ip_user, $project_name) {

        $project_content = '';
        //monta a query
        $this->db->select('project_content');
        $this->db->from('layoutproject');
        $this->db->where('ip_user', $ip_user);
        $this->db->where('project_name', $project_name);
        //executa a busca do registro
        $query = $this->db->get();
        if ( $query->num_rows() > 0 ) {
        //se encontrou o registro, retorna o conteudo do projeto
            $row = $query->row();
            $project_content = $row->project_content;
        }
        return $project_content;
    }

}

/* End of file mlayoutprojectdao.php */
/* Location: ./system/application/models/mlayoutprojectdao.php */